package com.lv.service.dialog

import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.github.gzuliyujiang.wheelpicker.widget.LinkageWheelLayout
import com.lv.common.imp.OnPositionMore
import com.lv.service.R
import com.lv.service.room.category.NewTelCategoryBean
import com.lv.service.weidget.picker.FristLikeProvider
import com.lxj.xpopup.core.BottomPopupView

/**
 * 作者： ygx
 * 创建日期：2022/10/10 10:32 AM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：
 */
class CategoryBottomPopupView(
    private val mContext: Context,
    private val mTitle: String = "",
    private val mAllBeans: List<NewTelCategoryBean>?,
    private var mWheelPosition1: Int = 0,
    private val positionListener: OnPositionMore<NewTelCategoryBean>? = null
) :
    BottomPopupView(mContext) {
    private var tvTitle: TextView? = null
    private var tvSure: TextView? = null
    private var wheelLinkage: LinkageWheelLayout? = null
    private var viewTop: View? = null

    override fun getImplLayoutId(): Int {
        return R.layout.category_bottom_popup
    }

    override fun onCreate() {
        super.onCreate()
        viewTop = findViewById<View>(R.id.view_top)
        tvTitle = findViewById<TextView>(R.id.tv_title)
        tvSure = findViewById<TextView>(R.id.tv_sure)
        wheelLinkage = findViewById<LinkageWheelLayout>(R.id.wheel_linkage)
        initView()
        initEvnet()
    }

    private fun initView() {
        tvTitle?.text = mTitle

        val thirdLikeProvider = FristLikeProvider(mAllBeans)
        wheelLinkage?.setData(thirdLikeProvider)

        wheelLinkage?.setDefaultValue(mWheelPosition1, 0, 0)
        wheelLinkage?.firstWheelView?.setDefaultPosition(mWheelPosition1)
        wheelLinkage?.firstWheelView?.visibility = View.VISIBLE
        wheelLinkage?.secondWheelView?.visibility = View.GONE
        wheelLinkage?.thirdWheelView?.visibility = View.GONE
    }

    private fun initEvnet() {
        wheelLinkage?.setOnLinkageSelectedListener { first, second, third ->
            mWheelPosition1 = wheelLinkage?.firstWheelView?.currentPosition ?: 0
//            mBinding.tvSearchCategory.text =
//                "${mAllBeans!![mWheelPosition1].name}-${mAllBeans[mWheelPosition1].telSecondCategories!![mWheelPosition2].name}"
        }
        viewTop?.setOnClickListener {
            dismiss()
        }
        findViewById<ImageView>(R.id.iv_close).setOnClickListener {
            dismiss()
        }
        tvSure?.setOnClickListener {
            positionListener?.onClick(
                mWheelPosition1, data = mAllBeans?.get(mWheelPosition1)
            )
            dismiss()
        }
    }

    fun setBottomBg(bg: Int) {
        tvSure?.setBackgroundResource(bg)
    }

    override fun onDestroy() {
        super.onDestroy()
    }

    override fun beforeDismiss() {
        super.beforeDismiss()

    }


}